package io.adrainty.bolee.file.feign.impl;

import io.adrainty.bolee.file.feign.IFileBusinessFeign;
import io.adrainty.bolee.file.models.entity.FileEntity;
import io.adrainty.bolee.file.service.IFileService;
import io.adrainty.bolee.framework.commons.basic.ResultDTO;
import io.adrainty.bolee.framework.commons.utils.ResultDTOUtil;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>FileBusinessFeignImpl</p>
 *
 * @author AdRainty
 * @version V1.0.0
 * @description IFileBusinessFeign
 * @since 2025/8/18 15:04:25
 */

@Tag(name = "文件业务Feign接口实现类")
@RestController
@RequestMapping("/file-feign")
public class FileBusinessFeignImpl implements IFileBusinessFeign {

    @Resource
    private IFileService fileService;

    @Override
    @DeleteMapping("/clear-file")
    @Operation(summary = "清理文件")
    public ResultDTO<Boolean> clearFile() {
        Boolean result = fileService.clearFile();
        return ResultDTOUtil.success(result);
    }

    @Override
    @DeleteMapping("/clear-file-id/{id}")
    @Operation(summary = "根据id清理文件")
    public ResultDTO<Boolean> clearFile(@PathVariable("id") Long id) {
        Boolean result = fileService.clearFileById(id);
        return ResultDTOUtil.success(result);
    }

    @Override
    @PostMapping("/bind-batch-file")
    @Operation(summary = "批量绑定文件")
    public ResultDTO<List<FileEntity>> bindBatchFile(@RequestBody List<FileEntity> fileVOs) {
        List<FileEntity> fileEntities = fileService.bindBatchFile(fileVOs);
        return ResultDTOUtil.success(fileEntities);
    }

    @Override
    @PostMapping(value = "/replace-bind-batch-file")
    @Operation(summary = "批量替换绑定文件")
    public ResultDTO<Boolean> replaceBindBatchFile(List<FileEntity> fileVOs) {
        Boolean result = fileService.replaceBindBatchFile(fileVOs);
        return ResultDTOUtil.success(result);
    }

    @Override
    @PostMapping("/find-in-business-ids")
    @Operation(summary = "根据业务ID查询文件")
    public ResultDTO<List<FileEntity>> findInBusinessIds(@RequestBody List<Long> businessIds) {
        List<FileEntity> fileVOs = fileService.findInBusinessIds(businessIds);
        return ResultDTOUtil.success(fileVOs);
    }

    @Override
    @DeleteMapping("/delete-by-business-ids")
    @Operation(summary = "根据业务ID删除文件")
    public ResultDTO<Boolean> deleteInBusinessIds(@RequestBody List<Long> businessIds) {
        Boolean result = fileService.deleteFileInBusinessIds(businessIds);
        return ResultDTOUtil.success(result);
    }

}
